#include "stdio.h"
int fun(int n,int sum);
main(){
	int n,i,n1,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&n1,&sum);
		printf("%d\n",fun(n1,sum));
	}

}
int fun(int n,int sum){
	int count=0,i,j,s,num;
	int a[100001];a[0]=a[100000]=0;
	for(i=0;i<n;i++){
		scanf("%d%d",&s,&num);
		if(s==1){
			a[a[0]+1]=num;a[0]++;
		}
		else{
			a[100000-a[100000]-1]=num;a[100000]++;
		}
	}
	if(a[0]==0||a[100000]==0)
		return 0;
	for(i=1,j=100000-a[100000];i<=a[0]||j<100000;){
		if(a[i]+a[j]<sum){
			i++;
		}
		else if(a[i]+a[j]>sum){
			j++;
		}
		else{
			count++;
			j++;i++;
		}
	}
	return count;
}